import Vue from 'vue';
import Vuex from 'vuex';
import getters from './getters';
import { getItem } from '@/utils/storage.js';
import * as Constant from '@/constant';

Vue.use(Vuex);

export default new Vuex.Store({
  modules: {},
  getters,
  state: {
    token: getItem(Constant.TOKEN) || '',
    is_env_dev: process.env.NODE_ENV === 'development', // 是否是开发环境
    config: null, // 页面配置信息
    defaultImg:
      'https://wxlsrecode2.oss-cn-shanghai.aliyuncs.com/coupon_model/2022-09-21/1191c50b-df10-4f7f-8d1e-1b45d12af72b.png', // 默认图 图裂
    selfPrize: [], // 定时开奖奖品
  },
  mutations: {
    setToken(state, token) {
      state.token = token;
    },
    setConfig(state, config) {
      state.config = config;
    },
    setSelfPrize(state, selfPrize) {
      state.selfPrize = selfPrize;
    },
  },
  actions: {
    // 分页查询抽奖模板（获取页面配置信息）
    async getConfig(context, config) {
      try {
        context.commit('setConfig', config);
      } catch (e) {}
    },
  },
});
